package com.antler.smt.portal.config;

import com.antler.smt.utils.RedisCacheUtil;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * Redis缓存配置
 *
 * @author vic
 * @date 2017-09-20 16:52
 */
@Configuration
@EnableCaching
public class RedisCacheConfig {
    /**
     * 生成key的策略
     *
     * @return
     */
    @Bean
    public KeyGenerator keyGenerator() {
       return RedisCacheUtil.keyGenerator();
    }

    /**
     * RedisTemplate配置
     *
     * @param factory
     * @return
     */
    @Bean
    public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
        return RedisCacheUtil.redisTemplate(factory);
    }
}
